home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 2.00 Begin Form frmTalk BackColor = &H8000000F& Caption = "Talk" ClientHeight = 5820 ClientLeft = 2148 ClientTop = 1620 ClientWidth = 7368 Height = 6468 Icon = TALK.FRX:0000 Left = 2100 LinkTopic = "Form1" ScaleHeight = 5820 ScaleWidth = 7368 Top = 1020 Width = 7464 Begin PowerTCP_TCP TCPlisten Flags = 0 Left = 1620 LocalDotAddr = "" OemLicense = "" RemoteHost = "" RemotePort = 7 Top = 900 End Begin PowerTCP_TCP TCPconnect Flags = 0 Left = 360 LocalDotAddr = "" OemLicense = "" RemoteHost = "" RemotePort = 7 Top = 900 End Begin TextBox txtRecv Height = 495 Left = 1200 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 1 Top = 0 Width = 1215 End Begin TextBox txtSend Height = 495 Left = 0 MultiLine = -1 'True ScrollBars = 2 'Vertical TabIndex = 0 Top = 0 Width = 1215 End Begin Menu mnuConversation Caption = "&Conversation" Begin Menu mnuCListen Caption = "&Listen..." End Begin Menu mnuCStopListening Caption = "&Stop Listening" Enabled = 0 'False End Begin Menu mnuCSep1 Caption = "-" End Begin Menu mnuCConnect Caption = "&Connect..." End Begin Menu mnuCDisconnect Caption = "&Disconnect" Enabled = 0 'False End Begin Menu mnuCSep2 Caption = "-" End Begin Menu mnuCExit Caption = "E&xit" End End Begin Menu mnuHelp Caption = "&Help" Begin Menu mnuHHowToUse Caption = "&How to Use Talk" End Begin Menu mnuHSep Caption = "-" End Begin Menu mnuHelpAboutTalk Caption = "&About Talk..." End End ' This sample application is copyright 1994 by Dart ' Communications. All rights reserved. ' You may use this application and any Visual Basic code ' within it for your own uses, and may modify it for your ' own needs. ' IMPORTANT: We MUST use the API MessageBox function ' instead of the VB MsgBox function. See the PowerTCP ' README for more information. Declare Function MessageBox Lib "User" (ByVal hWnd As Integer, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Integer) As Integer Declare Sub ShellAbout Lib "SHELL.DLL" (ByVal hWnd As Integer, ByVal AppName As String, ByVal AppInfo As String, ByVal hIcon As Integer) Const BorderWidth% = 30 ' Show parameters Const MODAL = 1 Const MODELESS = 0 ' MsgBox parameters Const MB_OK = 0 ' OK button only Sub Form_Resize () On Error Resume Next ' In case we get some kind ' of weird number because ' the form gets too small txtSend.Left = BorderWidth txtSend.Top = BorderWidth txtRecv.Top = BorderWidth txtSend.Height = ScaleHeight - 2 * BorderWidth txtRecv.Height = txtSend.Height txtSend.Width = (ScaleWidth - 3 * BorderWidth) / 2 txtRecv.Width = txtSend.Width txtRecv.Left = txtSend.Width + 2 * BorderWidth End Sub Sub Form_Unload (Cancel As Integer) End End Sub Sub mnuCConnect_Click () frmConnect.Show MODAL If frmConnect.Tag = True Then tcpConnect.RemoteHost = frmConnect.txtHostName tcpConnect.RemotePort = Val(frmConnect.txtPort) tcpConnect.Action = CONNECT End If frmConnect.Tag = "" End Sub Sub mnuCDisconnect_Click () tcpConnect.Action = CLOSECOMM End Sub Sub mnuCExit_Click () tcpListen.Action = ABORTCOMM tcpConnect.Action = ABORTCOMM End End Sub Sub mnuCListen_Click () ' Hide the host name from the connect dialog frmConnect.Label1.Visible = False frmConnect.txtHostName.Visible = False frmConnect.Show MODAL If frmConnect.Tag = True Then tcpListen.LocalPort = Val(frmConnect.txtPort) tcpListen.Action = LISTEN End If frmConnect.Label1.Visible = True frmConnect.txtHostName.Visible = True frmConnect.Tag = "" End Sub Sub mnuCStopListening_Click () tcpListen.Action = CLOSECOMM End Sub Sub mnuHelpAboutTalk_Click () ShellAbout Me.hWnd, "PowerTCP Talk Sample Application", "Talk Version 1.0 1994 Dart Communications" & Chr$(10) & "(315) 841-8106", Me.Icon End Sub Sub mnuHHowToUse_Click () Msg$ = "To use Talk, first begin the Talk application" Msg$ = Msg$ + " on one computer. Then click on Listen..." Msg$ = Msg$ + " from the File menu, so that Talk" Msg$ = Msg$ + " is listening on a certain port. Next," Msg$ = Msg$ + " begin Talk on another computer." suc% = MessageBox(Me.hWnd, Msg$, "How to Use Talk: Page 1/3", 0) Msg$ = "Choose Connect... from the File menu," Msg$ = Msg$ + " and fill in the computer name of the" Msg$ = Msg$ + " first computer and the port it was" Msg$ = Msg$ + " listening on." suc% = MessageBox(Me.hWnd, Msg$, "How to Use Talk: Page 2/3", 0) Msg$ = " Now both computers can communicate" Msg$ = Msg$ + " by typing in the left text box." Msg$ = Msg$ + " Whatever appears in the left text box" Msg$ = Msg$ + " will also appear in the right text" Msg$ = Msg$ + " box on the other computer." & Chr$(10) Msg$ = Msg$ + Chr$(10) & "Choose Disconnect from" Msg$ = Msg$ + " the File menu on either computer to" Msg$ = Msg$ + " end the connection." suc% = MessageBox(Me.hWnd, Msg$, "How to Use Talk: Page 3/3", 0) End Sub Sub tcpConnect_Connect () mnuCConnect.Enabled = False mnuCDisconnect.Enabled = True End Sub Sub tcpConnect_Exception (ErrorCode As Integer, ErrorDesc As String) If ErrorCode = PT_CLOSED Or ErrorCode = PT_ABORTED Then suc% = MessageBox(Me.hWnd, "Connection to host lost", "Talk", MB_OK) mnuCConnect.Enabled = True mnuCDisconnect.Enabled = False Else suc% = MessageBox(Me.hWnd, ErrorDesc & "(" & Format$(ErrorCode) & ").", "Talk", MB_OK) ' Destroy the connection tcpConnect.Action = CLOSECOMM End If End Sub Sub tcpConnect_Recv (RecvData As String) ' We have to check if any of the characters received ' are carriage returns or backspaces, and process ' them accordingly For i = 1 To Len(RecvData) Select Case Mid$(RecvData, i, 1) Case Chr$(13) ' Carriage return ' Even though only a Chr$(13) is sent, under ' Windows a return is Chr$(13)+Chr$(10). txtRecv = txtRecv & Chr$(13) & Chr$(10) Case Chr$(8) ' Backspace txtRecv = Left$(txtRecv, Len(txtRecv) - 1) Case Else ' Normal txtRecv = txtRecv + Mid$(RecvData, i, 1) End Select Next i End Sub Sub tcpListen_Accept (NewSession As Long) ' Only create a new session if no session currently ' exists If tcpConnect.State = CLOSED Then tcpConnect.Session = NewSession Else suc% = MessageBox(Me.hWnd, "Talk could not accept a new connection from a remote computer; only one at a time is allowed." & Chr$(10) & Chr$(10) & "If you are trying to connect to yourself, you must use two copies of Talk, and have one connect to the other.", "Connection Refused", 0) End If End Sub Sub tcpListen_Exception (ErrorCode As Integer, ErrorDesc As String) If ErrorCode = PT_CLOSED Or ErrorCode = PT_ABORTED Then suc% = MessageBox(Me.hWnd, "Listening stopped", "Talk", MB_OK) mnuCListen.Enabled = True mnuCStopListening.Enabled = False Else suc% = MessageBox(Me.hWnd, ErrorDesc & "(" & Format$(ErrorCode) & ").", "Talk", MB_OK) ' Stop listening tcpListen.Action = CLOSECOMM End If End Sub Sub tcpListen_Listen () mnuCListen.Enabled = False mnuCStopListening.Enabled = True End Sub Sub txtRecv_KeyPress (KeyAscii As Integer) Msg$ = "To send text, type in the left box. The right" Msg$ = Msg$ + " box is where all received text is" Msg$ = Msg$ + " displayed." suc% = MessageBox(Me.hWnd, Msg$, "Talk", 0) ' Prevent the character from appearing KeyAscii = 0 End Sub Sub txtSend_KeyPress (KeyAscii As Integer) If tcpConnect.State = CONNECTED Then ' Make sure the character appears at the end txtSend.SelStart = Len(txtSend) tcpConnect.Send = Chr$(KeyAscii) Else ' Prevent the character from appearing KeyAscii = 0 End If End Sub